<?php

/**
 * @fileoverview    美啦用户修改密码
 * @author          zhanglei11
 * @date            Thu Jan 05 14:34:25 CST 2012
 * @copyright       sina meila
 */

include_once '../../__global.php';
include_once SERVER_ROOT_PATH.'/include/ml_function_lib.php';

class aj_dellike extends ml_controller{
    
    /*
    =$p['pid'];
       $aid =$p['aid'];
       $cid = $p['cid'];
       $uid = $p['uid'];
       $type = $p['type'];
       */
    private $pid ;
    private $aid;
    private $cid;
    private $uid;
    private $type;
//    private $pwd_confirm;
    

    function initParam() {
        $this->pid = $this->input('pid','P');                // 图片id
        $this->aid = $this->input('aid','P');                    // 相册id
        $this->cid = $this->input('cid','P');                    // 类型id
        $this->uid = $this->input('uid','P');                    // uid
        $this->type = $this->input('type','P');                    // 类型
        
    }
    
    function main() {

        
        // 获取当前登录用户 id        
        $uid = $this->__visitor['uid'];
        $oAccount = new ml_model_dbUserAccount();
        
        //获取用户信息        
        $rs = $oAccount->getAccountById($uid);
        $accountInfo = $oAccount->get_data();
        
        if(!is_null($_COOKIE['LM_UNLOGIN_LIKE'])) {
           $likeids =  explode(',',$_COOKIE['LM_UNLOGIN_LIKE']);
           if(in_array($this->pid,$likeids)) {  //  如果在cookie里 就去除掉。
               $key = array_search($this->pid, $likeids);
               unset($likeids[$key]);
               setcookie('LM_UNLOGIN_LIKE',implode(',',$likeids),time()+86400,'','.meila.com' );
           }
        }
        
        /*if(!is_null($_COOKIE['LM_UNLOGIN_LIKE'])) {
           $likeids =  explode(',',$_COOKIE['LM_UNLOGIN_LIKE']);
           if(!in_array($pid,$likeids)) {  //  如果不在cookie里 
               $likeids[] = $pid;
               setcookie('LM_UNLOGIN_LIKE',implode(',',$likeids) ,time()+86400,'','.sina.com.cn');
//               $file_log->logger($p);
               $file_log->run();
           }else {
               return -1;   //  重复喜欢             
           }
         }else {
             setcookie('LM_UNLOGIN_LIKE',$pid,time()+86400,'','.sina.com.cn');
             $file_log->run();
         }  
         */
        $oMeilaPic = new ml_model_admin_dbMeilaPic();
        $rs = $oMeilaPic->getPicByPid($this->pid);
        if($rs == false) $msg = '未找到图片信息';
        
        $pic = $oMeilaPic->get_data();
        
        
        //    未登录登录 来改变like_visitor
        
        $where = ' pic_id = \''.$this->pid.'\'';
        $set = array('like_visitor'=>$pic['like_visitor'] - 1);
        $rs = $oMeilaPic->update($set,$where);
        
        $like_cnt = gb_function_lib::getVitrulCnt($this->pid,$pic['like_visitor'] + $pic['like_user'] - 1);
        
        if($rs) { //  成功
            $this->api_output(ML_RCODE_SUCC,array('likecnt'=>$like_cnt));
        }else {   //  修改密码失败
            $this->api_output(ML_RCODE_FAIL);
        }
    }



    function checkParam(){
        $this->check_referer();
//        $this->pwd_confirm = $this->input('pwd_confirm');    //确认密码
        
    }

}

new aj_dellike();

